package LeetCode;

import java.util.Arrays;

public class LC_624_MaximumDistanceinArrays {

    public static void main(String[] args) {

    }

    public class Solution {
        public int maximumProduct(int[] nums) {
            Arrays.sort(nums);
            int i = 0;
            int j = nums.length - 1;
            int result = 0;
            if (nums[j] <= 0) {
                result = nums[j] * nums[j - 1] * nums[j - 2];
            } else {
                int valueOfFront = nums[i] * nums[i + 1];
                int valueOfBehind = nums[j - 1] * nums[j - 2];
                if (valueOfFront > valueOfBehind) {
                    result = nums[j] * valueOfFront;
                } else {
                    result = nums[j] * valueOfBehind;
                }
            }
            return result;
        }
    }

}